const http = require('http');
const routes = require('./处理文件后缀名/routes')
const ejs = require('ejs')
const url = require('url');

http.createServer((req, res)=>{
    //创建静态web服务
    if(routes.static(req,res,'static')) return;
    console.log(req.method);

    let pathname = url.parse(req.url).pathname; 
    // http://127.0.0.1:3000/news     pathname=/news
    let pathname2 = pathname.replace('/','');   //把斜杠替换为空

    try{
        routes[pathname2](req,res)
    }catch(error){
        routes['error'](req,res)
    }
    
   
    
}).listen(8081);
console.log("Server runing at http://127.0.0.1:8081/");
